package com.liu.controls;

import com.liu.keeppwd.R;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;

public class MyWaitAnimDialog extends MySimpleDialog {
	private static AnimationDrawable anim;

	public MyWaitAnimDialog(Context con) {
		super(con, null, null);
		ImageView iv = new ImageView(con);
		iv.setImageResource(R.drawable.wait);
		iv.setMaxWidth(180);
		iv.setMaxHeight(180);
		iv.setScaleType(ScaleType.FIT_XY);
		iv.setBackgroundColor(Color.TRANSPARENT);
		LinearLayout LL = new LinearLayout(con);
		LL.setGravity(0x10);
		LL.addView(iv);

		anim = (AnimationDrawable) iv.getDrawable();
		this.setView(LL);
		this.setOnKeyListener(new DialogInterface.OnKeyListener() {

			@Override
			public boolean onKey(DialogInterface dialog, int keyCode,
					KeyEvent event) {
				if (keyCode == KeyEvent.KEYCODE_BACK) {
					return true;
				}
				return false;
			}

		});
		this.SetNoConBG();
		this.SetNoTitle();
		this.setCanceledOnTouchOutside(false);
	}

	@Override
	public void show() {
		super.show();
		if (!anim.isRunning()) {
			anim.start();
		}
	}

	@Override
	public void OnDismissListener(DialogInterface dialog) {
		super.OnDismissListener(dialog);
		anim.stop();
	}

}
